using System;
using System.Drawing;

namespace ICSharpCode.TextEditor.Document
{
    public class TextMarker : ISegment
    {
        [CLSCompliant(false)]
        protected int offset = -1;

        [CLSCompliant(false)]
        protected int length = -1;

        private TextMarkerType textMarkerType;

        private Color color;

        private Color foreColor;

        private string toolTip = null;

        private bool overrideForeColor = false;

        public int Offset
        {
            get
            {
                return offset;
            }
            set
            {
                offset = value;
            }
        }

        public int Length
        {
            get
            {
                return length;
            }
            set
            {
                length = value;
            }
        }

        public TextMarkerType TextMarkerType => textMarkerType;

        public Color Color => color;

        public Color ForeColor => foreColor;

        public bool OverrideForeColor => overrideForeColor;

        public bool IsReadOnly { get; set; }

        public string ToolTip
        {
            get
            {
                return toolTip;
            }
            set
            {
                toolTip = value;
            }
        }

        public int EndOffset => checked(offset + length - 1);

        public override string ToString()
        {
            return $"[TextMarker: Offset = {offset}, Length = {length}, Type = {textMarkerType}]";
        }

        public TextMarker(int offset, int length, TextMarkerType textMarkerType)
            : this(offset, length, textMarkerType, Color.Red)
        {
        }

        public TextMarker(int offset, int length, TextMarkerType textMarkerType, Color color)
        {
            if (length < 1)
            {
                length = 1;
            }
            this.offset = offset;
            this.length = length;
            this.textMarkerType = textMarkerType;
            this.color = color;
        }

        public TextMarker(int offset, int length, TextMarkerType textMarkerType, Color color, Color foreColor)
        {
            if (length < 1)
            {
                length = 1;
            }
            this.offset = offset;
            this.length = length;
            this.textMarkerType = textMarkerType;
            this.color = color;
            this.foreColor = foreColor;
            overrideForeColor = true;
        }
    }
}
